﻿#region License, Terms and Conditions
//
// TaskService.cs
//
// Authors: Kori Francis <twitter.com/djbyter>
// Copyright (C) 2012 Kori Francis. All rights reserved.
// 
// THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW:
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#endregion

namespace BugHerder.Core
{
    #region Imports
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    #endregion

    /// <summary>
    /// TODO
    /// </summary>
    public class TaskService : BugHerdApiBase
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="username">The API username to use when accessing the API</param>
        /// <param name="password">The API password to use when accessing the API</param>
        public TaskService(string username, string password)
            : base(username, password)
        { }

        /// <summary>
        /// Get a full list of tasks for a project, including archived tasks.
        /// </summary>
        /// <returns>The list of tasks</returns>
        public IEnumerable<Task> All(int projectId)
        {
            return GetRequest<List<Task>>("/projects/{0}/tasks", projectId);
        }

        /// <summary>
        /// List details of a task in a given project, includes a list of comments.
        /// </summary>
        /// <param name="projectId">The id of the project to retrieve</param>
        /// <param name="taskId">The id of the task to retrieve</param>
        /// <returns>The retrieved task, including a list of comments</returns>
        public Task Single(int projectId, int taskId)
        {
            return GetRequest<Task>("/projects/{0}/tasks/{1}", projectId, taskId);
        }

        /// <summary>
        /// Add a new task in a project.
        /// </summary>
        /// <param name="project">The task to create</param>
        /// <returns>The created task</returns>
        public Task Create(int projectId, Task task)
        {
            return PostRequest<Task, Task>(task, "/projects/{0}/tasks", projectId);
        }

        /// <summary>
        /// Update one of the tasks in a project.
        /// </summary>
        /// <param name="project">The task to update</param>
        public void Update(int projectId, Task task)
        {
            PutRequest<Task, Task>(task, "/projects/{0}/tasks/{1}", projectId, task.Id);
        }
    }
}
